/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import models.Login;

/**
 *
 * @author Maria Sophia
 */
public class LoginJDBC implements LoginDAO {

    @Override
    public void inserir(Login l) throws DAOException {
        try {
            Connection conn = FabricaConexao.getConnection();
            Statement st = conn.createStatement();
            String sql = "insert into login (nome,senha,tipo,campus,codcli)"
                    + " values ('" + l.getUsuario() + "','" + l.getSenha()+ "','" + l.getTipo() + "','"
                    + l.getCampus() + "','" + l.getCodcli()+ "');";

            st.executeUpdate(sql);
            conn.close();

        } catch (ErroConexao | SQLException ex) {
            throw new DAOException(ex);
        }
    }

    @Override
    public void remover(Login l) throws DAOException {
        Connection conn;
        try {
            conn = FabricaConexao.getConnection();
            Statement st = conn.createStatement();
            String sql = "delete from login where id='"+l.getId()+"';";
            st.executeUpdate(sql);
            conn.close();
        } catch (ErroConexao | SQLException ex) {
            throw new DAOException(ex);
        }

    }
}
